package com.lancoo.znbkxx.teacher.ui.adapter

import android.content.Context
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.aibkTestCoach.aibkTools.LancooMethod
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerAdapter
import com.lancoo.znbkxx.teacher.aibkTestCoach.kBase.KBaseRecyclerViewHolder
import com.lancoo.znbkxx.teacher.aibkTestCoach.networkRequest.entity.ClassStuNumUpDownInfor
import kotlinx.android.synthetic.main.aibk_adapter_item_estimate_grade_student.view.*

class AibkEstimateGradeStuNumAdapter(
        val context: Context?,
        val classStuNumUpDownInfor: ClassStuNumUpDownInfor,
        val isUpScore:Boolean
): KBaseRecyclerAdapter() {

    override fun getHolderView(parent: ViewGroup?, position: Int): View? {
        return LayoutInflater.from(context)
                .inflate(R.layout.aibk_adapter_item_estimate_grade_student, parent, false)
    }

    override fun onBindViewHolder(holder: KBaseRecyclerViewHolder, position: Int) {
        if(position == 0){
            holder.convertView.TvStuScoreChange.setCompoundDrawables(null, null, null, null)
        }else{
            if(isUpScore) {
                val stuName = classStuNumUpDownInfor.StuUpList[position - 1].StuName
                val stuID = classStuNumUpDownInfor.StuUpList[position - 1].StuID
                val stuScore = classStuNumUpDownInfor.StuUpList[position - 1].StuScore
                var upScore = classStuNumUpDownInfor.StuUpList[position - 1].UpScore

                holder.convertView.TvStuName.text = stuName
                holder.convertView.TvStuID.text = stuID
                holder.convertView.TvStuScore.text = LancooMethod.killlingDouble(stuScore)
                holder.convertView.TvStuScoreChange.text = "+ " + LancooMethod.killlingDouble(Math.abs(upScore))

                holder.convertView.TvStuName.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuID.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuScore.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuScoreChange.setTextColor(context!!.resources.getColor(R.color.textColor2))

                val drawable = context.resources.getDrawable(R.mipmap.aibk_icon_score_up)
                drawable.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
                holder.convertView.TvStuScoreChange.setCompoundDrawables(null, null, drawable, null)
            }else{
                val stuName = classStuNumUpDownInfor.StuDownList[position - 1].StuName
                val stuID = classStuNumUpDownInfor.StuDownList[position - 1].StuID
                val stuScore = classStuNumUpDownInfor.StuDownList[position - 1].StuScore
                var downScore = classStuNumUpDownInfor.StuDownList[position - 1].DownScore

                holder.convertView.TvStuName.text = stuName
                holder.convertView.TvStuID.text = stuID
                holder.convertView.TvStuScore.text = LancooMethod.killlingDouble(stuScore)
                holder.convertView.TvStuScoreChange.text = "+ " + LancooMethod.killlingDouble(Math.abs(downScore))

                holder.convertView.TvStuName.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuID.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuScore.setTextColor(context!!.resources.getColor(R.color.textColor2))
                holder.convertView.TvStuScoreChange.setTextColor(context!!.resources.getColor(R.color.textColor2))

                val drawable = context.resources.getDrawable(R.mipmap.aibk_icon_score_down)
                drawable.setBounds(0, 0, drawable.minimumWidth, drawable.minimumHeight)
                holder.convertView.TvStuScoreChange.setCompoundDrawables(null, null, drawable, null)
            }
        }
    }

    override fun getItemCount(): Int {
        var infoSize = 0
        if(isUpScore){
            if(classStuNumUpDownInfor.StuUpList !=null) {
                infoSize = classStuNumUpDownInfor.StuUpList.size
            }
        }else{
            if(classStuNumUpDownInfor.StuDownList !=null) {
                infoSize = classStuNumUpDownInfor.StuDownList.size
            }
        }
        return infoSize+1
    }

    override fun getItemViewType(position: Int): Int {
        return position
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

}